package com.heima.socket.udp.multicast;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        /**
         * 组播发送
         */

        // 1. 创建MulticastSocket对象
        MulticastSocket ms = new MulticastSocket();

        // 2. 创建DatagramPacket对象
        String str = "Hello MultiSocket!";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("224.0.0.1");
        int port = 10000;

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        // 3. 发送数据
        ms.send(dp);

        // 4. 释放资源
        ms.close();
    }
}
